package com.example.factory.practice;

import java.util.ArrayList;
import java.util.List;

public class ChainOfResponsibilityFilter {
    public static void main(String[] args) {
        StepChain filterChain = new StepChain();
        filterChain.addFilter(new MakeFairStep()).addFilter(new WashVegetablesStep());
        filterChain.doFilter();
    }
}

interface Step {
    boolean doFilter();
}

class StepChain implements Step {
    List<Step> stepChain = new ArrayList<>();

    StepChain addFilter(Step step) {
        stepChain.add(step);
        return this;
    }

    @Override
    public boolean doFilter() {
        for (Step f : this.stepChain) {
            if (!f.doFilter()) return false;
        }
        return true;
    }
}

class MakeFairStep implements Step {

    @Override
    public boolean doFilter() {
        System.out.println("MakeFairStep");
        return true;
    }
}

class WashVegetablesStep implements Step {

    @Override
    public boolean doFilter() {
        System.out.println("WashVegetablesStep");
        return true;
    }
}
